package com.naiterui.ehp.bs.search.controller.inner;

import java.util.List;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.naiterui.common.repository.page.PageVO;
import com.naiterui.ehp.bp.bo.statistics.AsConsultRecordBO;
import com.naiterui.ehp.bp.bo.statistics.AsOrderRecordBO;
import com.naiterui.ehp.bp.bo.statistics.AsProductRecordBO;
import com.naiterui.ehp.bp.bo.statistics.AsRecipelRecordBO;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.support.utils.JsonMapper;
import com.naiterui.ehp.bs.search.service.IStatisticsService;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 内部报表记录接口
 * 
 * @author yangfuya
 * @since 2022/2/10
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("search/inner/statistics")
public class InnerStatisticsController {
    private final IStatisticsService statisticsService;

    /**
     * 创建经纪人数据统计-问诊相关记录
     */
    @PostMapping("/consult/record")
    public void createConsultRecordIndex(@RequestBody AsConsultRecordBO consultRecordBO) {
        log.info("记录问诊相关记录{}", JsonMapper.toJson(consultRecordBO));
        this.statisticsService.createConsultRecordIndex(consultRecordBO);
    }

    /**
     * 查询经纪人数据统计-问诊相关记录
     */
    @GetMapping("/consult/record")
    public List<AsConsultRecordBO> findConsultRecordIndex(String yesterday) throws BusinessException {
        return this.statisticsService.findConsultRecordIndex(yesterday);
    }

    /**
     * 创建经纪人数据统计-药品售卖相关记录
     */
    @PostMapping("/product/record")
    public void createProductRecordIndex(@RequestBody AsProductRecordBO drugRecordBO) {
        log.info("记录药品售卖相关记录{}", JsonMapper.toJson(drugRecordBO));
        this.statisticsService.createProductRecordIndex(drugRecordBO);
    }

    /**
     * 查询经纪人数据统计-药品售卖相关记录
     */
    @GetMapping("/product/record")
    public List<AsProductRecordBO> findProductRecordIndex(String yesterday) throws BusinessException {
        return this.statisticsService.findProductRecordIndex(yesterday);
    }

    /**
     * 创建经纪人数据统计-订单相关记录
     */
    @PostMapping("/order/record")
    public void createOrderRecordIndex(@RequestBody AsOrderRecordBO orderRecordBO) {
        log.info("记录订单相关记录：{}", JsonMapper.toJson(orderRecordBO));
        this.statisticsService.createOrderRecordIndex(orderRecordBO);
    }

    /**
     * 查询经纪人数据统计-订单相关记录
     */
    @GetMapping("/order/record")
    public List<AsOrderRecordBO> findOrderRecordIndex(String yesterday) throws BusinessException {
        return this.statisticsService.findOrderRecordIndex(yesterday);
    }

    /**
     * 创建经纪人数据统计-处方相关记录
     */
    @PostMapping("/recipel/record")
    public void createRecipelRecordIndex(@RequestBody AsRecipelRecordBO recipelRecordBO) {
        log.info("记录处方相关记录：{}", JsonMapper.toJson(recipelRecordBO));
        this.statisticsService.createRecipelRecordIndex(recipelRecordBO);
    }

    /**
     * 查询昨日经纪人数据统计-处方相关记录
     */
    @GetMapping("/recipel/record")
    public List<AsRecipelRecordBO> findRecipelRecordIndex(String yesterday) throws BusinessException {
        return this.statisticsService.findRecipelRecordIndex(yesterday);
    }

    /**
     * 修改经纪人数据统计-处方相关记录
     */
    @PostMapping("/recipel/record/update")
    public void updateRecipelRecordIndex(@RequestParam Long recipelId) throws BusinessException {
        this.statisticsService.updateRecipelRecordIndex(recipelId);
    }

    /**
     * 分页获取订单
     */
    @GetMapping("/order/record/page")
    public PageVO<AsOrderRecordBO> findOrderPage(Long doctorId, String orderSn, int pageNo, int pageSize)
        throws BusinessException {
        return this.statisticsService.findOrderPage(doctorId, orderSn, pageNo, pageSize);
    }
}
